package com.imooc.converter;

import com.imooc.dataobject.OrderMaster;
import com.imooc.dto.OrderDto;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能描述: <br>
 * (Description: 将订单对象转换为orderDto对象)
 *
 * @Author:Mr. xyb
 * @Date: 2018/5/18 16:56
 * @since: 1.8.0
 * @version: 1.0.0
 */
public class OrderMaster2OrderDtoConverter {

    /**
     * 将orderMaster对象转换为orderDto
     *
     * @param orderMaster
     * @return
     */
    public static OrderDto convert(OrderMaster orderMaster) {
        OrderDto orderDto = new OrderDto();
        // 通过copy属性值赋值
        BeanUtils.copyProperties(orderMaster, orderDto);
        return orderDto;
    }

    /**
     * 将订单集合循环转换为orderDto集合
     *
     * @param orderMasters
     * @return
     */
    public static List<OrderDto> convert(List<OrderMaster> orderMasters) {
        return orderMasters.stream().map(e -> convert(e)).collect(Collectors.toList());
    }

}
